package trb.complexshield.bool.distance;

import no.hrp.hvrc.utils.j3d.Mat4;
import no.hrp.hvrc.utils.j3d.Vec3;
import trb.complexshield.bool.IntersectableSphere;

public class SphereDistance implements DistanceProducer {

    private IntersectableSphere sphere;
    Mat4 worldToLocal;

    public SphereDistance(IntersectableSphere sphere) {
        this.sphere = sphere;
        worldToLocal = sphere.getWorldToLocal();
    }

    @Override
    public float getDistance(Vec3 pos) {
        Vec3 local = worldToLocal.transformAsPoint(new Vec3(pos));
        return local.length() - sphere.getRadius();
    }

}
